package com.codingfuture.erp_system.service.impl;

import com.codingfuture.erp_system.dto.DepDto;
import com.codingfuture.erp_system.entity.Dep;
import com.codingfuture.erp_system.mapper.DepMapper;
import com.codingfuture.erp_system.service.DepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DepServiceImpl implements DepService {

    @Autowired
    private DepMapper depMapper;

    @Override
    public DepDto findById(Integer id) {
        return depMapper.findById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insert(Dep dep) {
        return depMapper.insert(dep) != 0;
    }

    @Override
    public List<Dep> findByAll(Dep dep) {
        return depMapper.findByAll(dep);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean update(Dep dep) {
        return depMapper.update(dep) != 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean delete(Integer id) {
        return depMapper.delete(id) != 0;
    }

    @Override
    public String nameExist(String name) {
        return depMapper.nameExist(name);
    }

}
